package com.webwork.lims.orders.dataobject;

import java.util.ArrayList;
import java.util.List;

import com.webwork.lims.common.dataobject.SuperEnum;

public enum OrderStatus implements SuperEnum {

	NOSET(SuperEnum.NOSET_CODE, SuperEnum.NOSET_MSG),

	/**
	 * 等待审核
	 */
	WAITING(1, "等待审核"),
	/**
	 * 已审核
	 */
	VERIFIED(2, "已审核"),
	/**
	 * 已发货
	 */
	DELIVERY(3, "已发货"),
	/**
	 * 已完成
	 */
	COMPLETE(4, "已完成"),
	/**
	 * 已取消
	 */
	CANCEL(5, "已取消"),
	/**
	 * 派送中
	 */
	DISPATCH(6, "派送中");
	
	private Integer code;
	private String msg;
	
	private OrderStatus(Integer code, String msg) {
		this.code = code;
		this.msg = msg;
	}
	
	@Override
	public Integer getCode() {
		return code;
	}
	
	@Override
	public String getMsg() {
		return msg;
	}
	
	public static OrderStatus[] useableValues() {
		List<OrderStatus> ret = new ArrayList<OrderStatus>();
		for (OrderStatus o : OrderStatus.values()) {
			if (o.code == OrderStatus.NOSET_CODE) {
				continue;
			}
			ret.add(o);
		}
		return ret.toArray(new OrderStatus[ret.size()]);
	}
	
	public static OrderStatus fromCode(Integer code) {
		for (OrderStatus o : OrderStatus.values()) {
			if (o.code.equals(code)) {
				return o;
			}
		}
		throw new IllegalArgumentException(code.toString());
	}

}
